home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cpptutor.arc / ITEMS.CPP < prev    next >
C/C++ Source or Header  |  1991-04-28  |  2KB  |  102 lines

  1. // Methods for class items
  2.  
  3. #include "iostream.h"
  4. #include "items.hpp"
  5.  
  6. items::items(void)
  7. {
  8.    keys_on_hand = FALSE;
  9.    candy_on_hand = FALSE;
  10.    ticket_on_hand = FALSE;
  11.    money_on_hand = FALSE;
  12. }
  13.  
  14.  
  15.  
  16.  
  17. void 
  18. items::add_item(word item_to_add)
  19. {
  20.    switch (item_to_add) {
  21.       case keys   : keys_on_hand = TRUE;
  22.                     break;
  23.       case candy  : candy_on_hand = TRUE;
  24.                     break;
  25.       case ticket : ticket_on_hand = TRUE;
  26.                     break;
  27.       case money  : money_on_hand = TRUE;
  28.                     break;
  29.       default     : break;
  30.    }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. void
  37. items::drop_item(word item_to_drop)
  38. {
  39.    switch (item_to_drop) {
  40.       case keys   : keys_on_hand = FALSE;
  41.                     break;
  42.       case candy  : candy_on_hand = FALSE;
  43.                     break;
  44.       case ticket : ticket_on_hand = FALSE;
  45.                     break;
  46.       case money  : money_on_hand = FALSE;
  47.                     break;
  48.       default     : break;
  49.    }
  50. }
  51.  
  52.  
  53.  
  54.  
  55. int
  56. items::item_here(word item_to_check)
  57. {
  58.    switch (item_to_check) {
  59.       case keys   : return keys_on_hand;
  60.                     break;
  61.       case candy  : return candy_on_hand;
  62.                     break;
  63.       case ticket : return ticket_on_hand;
  64.                     break;
  65.       case money  : return money_on_hand;
  66.                     break;
  67.       default     : break;
  68.    }
  69. }
  70.  
  71.  
  72.  
  73.  
  74. void
  75. items::list_items(void)
  76. {
  77.    if (keys_on_hand)
  78.       cout << "You have the keys to your car.\n";
  79.    if (candy_on_hand)
  80.       cout << "You have two candy bars.\n";
  81.    if (ticket_on_hand)
  82.       cout << "You have a ticket for your dream vacation.\n";
  83.    if (money_on_hand) 
  84.       cout << "You have a couple of dollars of loose change.\n";
  85.  
  86.  
  87.  
  88.  
  89. void
  90. items::list_items_in_room(void)
  91. {
  92.    if (keys_on_hand)
  93.       cout << "There are car keys here.\n";
  94.    if (candy_on_hand)
  95.       cout << "There are some candy bars here.\n";
  96.    if (ticket_on_hand)
  97.       cout << "There is an airplane ticket here.\n";
  98.    if (money_on_hand) 
  99.       cout << "There is some money here.\n";
  100.